﻿using System.Diagnostics;

namespace findthebiggestprimenumberbelow100000
{
    internal class Program
    {

        /// <summary>
        /// 输出这个数的最大质数
        /// </summary>
        /// <param name="args"></param>
        
        //可更改num
        const long num = 100000;                             
        static void Main(string[] args)
        {


            long k = 0;
            //运行时间的开始
            Stopwatch stopwatch = new Stopwatch();          
            stopwatch.Start();           
            //Console.WriteLine("请输入一个较大的整数");
            //string input=Console.ReadLine();
            //int num = int.Parse(input);
            for (long i = num; i > 1; i--)
            {
                for (long j = i - 1; j > Math.Sqrt(i); j--)
                {
                    if (i % j == 0)                                      //如果有因数，则跳出循环
                        break;
                    if (j == Math.Ceiling(Math.Sqrt(i)) && i % j != 0)   //只需要遍历以算术平方根为中点的一半
                    {
                        Console.WriteLine($"{num}最大的质数是{i}");
                        k = i;
                        break;
                    }
                }
                if (i < k) break;
            }
            stopwatch.Stop();
            TimeSpan runtime = stopwatch.Elapsed;                           //运行时间结束
            Console.Write($"runtime:{runtime.TotalMilliseconds}毫秒");      //输出运行时间

        }
    }
}